package model;

import javax.swing.ImageIcon;

/**
 * A tile in the region map.
 */
public class Square implements ModelUpdate{

	private final SquareType type;
	private boolean hasPellet;

	/**
	 * Constructs a new square with the specified type.
	 * @param type the type of this square.
	 */
	public Square(final SquareType type){
		this.type = type;
		this.hasPellet = type.hasPellet();
	}

	/**
	 * Returns the icon to use to draw this square on screen.
	 */
	@Override public ImageIcon getIcon(){
		return this.type.getIcon();
	}
	
	public Square copy(){
		Square square = new Square(type);
		square.hasPellet = hasPellet;
		return square;
	}

	/**
	 * Returns true if the player cannot walk through this tile.
	 * @return true if the player cannot walk through this tile.
	 */
	public boolean isBlocking(){
		return this.type.isBlocking();
	}

	/**
	 * See if Square and Object are equal.
	 * @param Object o is the object to be compared with.
	 * @return true if o is equal to this square, else false.
	 */
	public boolean equals(Object o){
		if(o instanceof Square){
			final Square square = (Square)o;
			if(square.type == type && type.hasPellet()==type.hasPellet()){
				return true;
			}
		}
		return false;
	}

	@Override public void update() {
	}

	/**
	 * Returns true if the square currently has a pellet in it.
	 * @return true if the square currently has a pellet in it.
	 */
	public boolean hasPellet() {
		return this.hasPellet;
	}

	/**
	 * Removes any pellet that may be contained in this square.
	 */
	public void removePellet() {
		this.hasPellet = false;
	}

}
